﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ViewBug : System.Web.UI.Page
{
    public static BugManagement bugMan;
    public static Bug bug;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["id"] == null)
                Response.Redirect("/");

            int bugId = int.Parse(Request.QueryString["id"]);
            bug = BugManagement.GetBug(bugId);

            User currentUser = Master.CurrentUserManagement.CurrentUser;

            if (currentUser.Role != (int)UserManagement.Role.Admin)
            {
                var query = from item in ApplicationGlobalVariables.KillDaBugsDatabase.User_Projects
                            where item.Username == currentUser.Username && item.ProjectId == bug.ProjectId
                            select 0;
                if (!query.Any())
                    Response.Redirect("/");
            }

            ltrBugId.Text = bug.BugId.ToString();
            ltrReportedUser.Text = bug.ReportedUser;
            ltrReportedUserRole.Text = EnumUtility.GetEnumNiceName((UserManagement.Role)bug.User.Role);

            ltrSummary.Text = bug.Summary;

            ddlPriority.Items.Add(EnumUtility.GetEnumNiceName((BugManagement.Priority)bug.Priority));

            ddlReproducability.Items.Add(EnumUtility.GetEnumNiceName((BugManagement.Reproducability)bug.Reproducability));

            if (bug.Resolution != null)
                ddlResolution.Items.Add(EnumUtility.GetEnumNiceName((BugManagement.Resolution)bug.Resolution));

            ddlSeverity.Items.Add(EnumUtility.GetEnumNiceName((BugManagement.Severity)bug.Severity));

            ddlStatus.Items.Add(EnumUtility.GetEnumNiceName((BugManagement.Status)bug.Status));

            ddlType.Items.Add(EnumUtility.GetEnumNiceName((BugManagement.Type)bug.Type));

            txtSummary.Text = bug.Summary;

            txtReproSteps.Text = bug.ReproductionSteps;

            txtDescription.Text = bug.Description;

            txtBugFoundInVersion.Text = bug.BugFoundInVersion;

            txtBugFoundInComponent.Text = bug.BugFoundInComponent;

            Reporting report = new Reporting();
            ltrBugReport.Text = report.GetReportBug(bug.BugId);
        }
    }
}